<?php

namespace App\Services\ApplyGoldCoinWithdraw;

use App\Models\Withdraw;

class RefuseGoldCoinWithdraw
{
	/**
	 * @var Withdraw
	 */
	protected $withdraw;

	public function __construct(Withdraw $withdraw)
	{
		$this->withdraw = $withdraw;
	}

	protected function handle()
	{
		$withdraw = $this->withdraw;

		if ($withdraw->isPaid()) return;

		$user = $withdraw->user;
		$data = ['withdraw_id' => $withdraw->id];

		account_balances($user)->plusRefusedWithdrawPrincipal($withdraw->actual_amount, $data);
		account_balances($user)->plusRefusedWithdrawCharge($withdraw->charge_amount, $data);
	}

	public function refuse()
	{
		$this->handle();
	}
}
